package de.upb.aquarium.water;

public class CircleWaveBuffer extends WaveBuffer {

	private CircleWave wave;

	public CircleWaveBuffer(
			int horizontalResolution,
			int verticalResolution,
			double width, double depth,
			int timeResolution,
			CircleWave wave) {
		super(horizontalResolution, verticalResolution, width, depth, timeResolution);
		
		this.wave = wave;
		init();
	}
	
	@Override
	protected void createWaves() 	 {
		double cX = wave.getCenterX();
		double cY = wave.getCenterY();
		
		// Waves left of center:
		CircleWave leftUpper	= wave.clone();
		CircleWave left			= wave.clone();
		CircleWave leftLower	= wave.clone();
		
		leftUpper.setCenter(-cX, -cY);
		left.setCenter(-cX, cY);
		leftLower.setCenter(-cX, 2*getDepth() - cY);
		
		addWave(leftUpper);
		addWave(left);
		addWave(leftLower);

		
		// Waves right of center:
		CircleWave rightUpper	= wave.clone();
		CircleWave right		= wave.clone();
		CircleWave rightLower	= wave.clone();
		
		rightUpper.setCenter(2*getWidth() - cX, -cY);
		right.setCenter(2*getWidth() - cX, cY);
		rightLower.setCenter(2*getWidth() - cX, 2*getDepth() - cY);
		
		addWave(rightUpper);
		addWave(right);
		addWave(rightLower);
		
		
		// Waves in center:
		CircleWave upper	= wave.clone();
		CircleWave center	= wave;
		CircleWave lower	= wave.clone();
		
		upper.setCenter(cX, -cY);
		lower.setCenter(cX, 2*getDepth() - cY);
		
		addWave(upper);
		addWave(center);
		addWave(lower);	
	}

	@Override
	public double getMaximalLifeTime() {
		
		double maxDistance = Math.sqrt(getDepth()*getDepth() + getWidth()*getWidth());
		double neededWavelengths = (2*maxDistance)/wave.getWaveLength() + 1;
		
		return neededWavelengths*wave.getRotationTime();
	}

}
